﻿using CrystalDecisions.CrystalReports.Engine;
using Ice.Lib.Report;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KineticWebCrystalExport
{
    internal class PubFun
    {
        public static void ShowReport(ReportDocument ReportData, string Title)
        {
            ReportForm ReportForm1 = new ReportForm();
            ReportForm1.ShowReport(ReportData, Title);
        }

        public static void ViewReport(string PrintProgram, DataSet ds, string rptName, string rptTitle = null)
        {
            //try
            //{

            //    if (rptTitle == null) rptTitle = rptName;
            //    if (!Directory.Exists(Application.StartupPath + @"\Temp"))
            //    {
            //        Directory.CreateDirectory(Application.StartupPath + @"\Temp");
            //    }
            //    ds.WriteXml(Application.StartupPath + @"\Temp\" + rptName + ".xml", XmlWriteMode.WriteSchema);
            //    ds.WriteXml(Application.StartupPath + @"\Temp\" + rptName + "_1.xml", XmlWriteMode.WriteSchema);
            //    //MessageBox.Show(Application.StartupPath + @"\Temp\" + rptName + ".xml");
            //    File.Copy(PrintProgram, Application.StartupPath + @"\Temp\" + rptName + ".rpt", true);
            //    for (int x = 1; x <= 1000; x++)
            //    {
            //        Application.DoEvents();
            //        System.Threading.Thread.Sleep(30);
            //    }

            //    if (EpiCrystalReport.IsRequiredCrystalRuntimeInstalled())
            //    {
            //        //会删除这两个文件
            //        EpiCrystalViewer Viewer = new EpiCrystalViewer(Application.StartupPath + @"\Temp\" + rptName + ".rpt", Application.StartupPath + @"\Temp\" + rptName + ".xml", rptTitle);
            //        Viewer.Show();

            //    }
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("ViewReport错误！" + e.Message);
            //}
        }
    }
}
